package model;

import entity.Employee;
import entity.Orders;
import entity.OrdersDetails;
import java.util.ArrayList;
import javax.swing.table.AbstractTableModel;

/**
 *
 * @author Noi
 */
public class EmployeeBorrowBooksTableModel extends AbstractTableModel {

    private manager.Manager manager;
    private ArrayList<Employee> alEmployee;

    public EmployeeBorrowBooksTableModel(manager.Manager manager) {
        this.manager = manager;
        this.alEmployee = new ArrayList<Employee>();
    }

    public void setAlEmployee(ArrayList<Employee> alEmployee) {
        this.alEmployee = alEmployee;
        this.fireTableDataChanged();
    }

    @Override
    public int getRowCount() {
        return this.alEmployee.size();
    }

    @Override
    public int getColumnCount() {
        return 4;
    }

    @Override
    public Object getValueAt(int rowIndex, int columnIndex) {
        Employee employee = this.alEmployee.get(rowIndex);
        ArrayList<Orders> alOrders = this.manager.getOrdersManager().getByEmployeeID(employee.getEmployeeID());
        ArrayList<OrdersDetails> alDetailsUnpaid = this.manager.getOrdersDetailsManager().getListOrdersDetailsUnpaid(alOrders);
        ArrayList<OrdersDetails> alDetails = this.manager.getOrdersDetailsManager().getListOrdersDetailsByOrdersList(alOrders);
        
        switch(columnIndex) {
            case 0:
                return employee.getEmployeeID();
            case 1:
                return employee.getEmployeeName();
            case 2:
                return alDetails.size();
            case 3:
                return alDetailsUnpaid.size();
            default:
                return null;
        }
    }

    @Override
    public String getColumnName(int column) {
        switch (column) {
            case 0:
                return "Employee ID";
            case 1:
                return "Employee Name";
            case 2:
                return "Total";
            case 3:
                return "Total number of books borrowed";
            default:
                return null;
        }
    }
    
    public Employee get(int index) {
        return this.alEmployee.get(index);
    }

    public int size() {
        return this.alEmployee.size();
    }
}